Skip to content

🐛 handle curtime(), curdate(), current_timestamp(), and now() MariaDB-specific translations in default values #100

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 3, 2025

Conversation

techouse
Copy link
Owner

@techouse techouse commented Jul 3, 2025

This pull request enhances the translation of MariaDB-specific default values to SQLite equivalents by adding support for more MySQL functions and updating the corresponding unit tests to ensure correctness.

Enhancements to MariaDB-to-SQLite translation:

  • Added support for translating MariaDB functions curtime(), curdate(), current_timestamp(), and now() to their SQLite equivalents (CURRENT_TIME, CURRENT_DATE, and CURRENT_TIMESTAMP) in the _translate_default_from_mysql_to_sqlite method of src/mysql_to_sqlite3/transporter.py.

Unit test updates:

  • Updated the test_translate_type_from_mysql_to_sqlite_all_valid_columns method in tests/unit/mysql_to_sqlite3_test.py to include test cases for curtime(), curdate(), current_timestamp(), and now() to validate the new translations. [1] [2]

Fixes #99

@techouse techouse self-assigned this Jul 3, 2025
@techouse techouse added the bug Something isn't working label Jul 3, 2025
Copy link

coderabbitai bot commented Jul 3, 2025

Walkthrough

The _translate_default_from_mysql_to_sqlite method in transporter.py was updated to recognise additional MySQL default value expressions as strings and translate them to their correct SQLite equivalents. Corresponding unit tests were also added to ensure these new cases are handled correctly.

Changes

File(s) Change Summary
src/mysql_to_sqlite3/transporter.py Enhanced _translate_default_from_mysql_to_sqlite to handle more MySQL default expressions as strings.
tests/unit/mysql_to_sqlite3_test.py Added parameterised tests for new MySQL default value cases to verify correct translation.

Sequence Diagram(s)

sequenceDiagram
    participant MySQLtoSQLite
    participant MySQL Column Definition
    participant SQLite Column Definition

    MySQL Column Definition->>MySQLtoSQLite: Provide default value (e.g., "curtime()", "current_timestamp()")
    MySQLtoSQLite->>MySQLtoSQLite: _translate_default_from_mysql_to_sqlite
    MySQLtoSQLite->>SQLite Column Definition: Output mapped SQLite default (e.g., DEFAULT CURRENT_TIME)
Loading

Assessment against linked issues

Objective Addressed Explanation
Correctly translate MySQL/MariaDB default values like "current_timestamp()", "now()", "curtime()", "curdate()" to corresponding SQLite defaults (DEFAULT CURRENT_TIMESTAMP, etc.) (#99)

Poem

A hop, a skip, a timestamp leap,
MySQL quirks no longer creep.
From "now()" to "curtime()"—all mapped right,
SQLite columns shine so bright.
With every test, a bunny cheer,
The data flows without a fear!
🐇✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between cdee3da and 0f774fc.

📒 Files selected for processing (2)
  • src/mysql_to_sqlite3/transporter.py (1 hunks)
  • tests/unit/mysql_to_sqlite3_test.py (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (17)
  • GitHub Check: Test (python3.9, mariadb:11.4, 0, false, 3.9)
  • GitHub Check: Test (python3.11, mariadb:10.6, 0, false, 3.11)
  • GitHub Check: Test (python3.13, mariadb:10.5, 0, false, 3.13)
  • GitHub Check: Test (python3.9, mariadb:10.6, 0, false, 3.9)
  • GitHub Check: Test (python3.12, mariadb:10.2, 0, false, 3.12)
  • GitHub Check: Test (python3.12, mariadb:10.4, 0, false, 3.12)
  • GitHub Check: Test (python3.12, mariadb:10.3, 0, false, 3.12)
  • GitHub Check: Test (python3.11, mariadb:10.3, 0, false, 3.11)
  • GitHub Check: Test (python3.10, mariadb:10.1, 1, false, 3.10)
  • GitHub Check: Test (python3.11, mariadb:10.2, 0, false, 3.11)
  • GitHub Check: Test (python3.12, mariadb:10.1, 1, false, 3.12)
  • GitHub Check: Test (python3.13, mariadb:10.0, 1, false, 3.13)
  • GitHub Check: Test (python3.11, mariadb:10.0, 1, false, 3.11)
  • GitHub Check: Test (python3.11, mariadb:5.5, 1, false, 3.11)
  • GitHub Check: Test (python3.12, mariadb:5.5, 1, false, 3.12)
  • GitHub Check: Test (python3.9, mariadb:5.5, 1, false, 3.9)
  • GitHub Check: Codacy Static Code Analysis
🔇 Additional comments (2)
src/mysql_to_sqlite3/transporter.py (1)

329-334: Excellent implementation of MySQL function default value translations!

The logic correctly handles the MySQL default value functions and translates them to appropriate SQLite equivalents. The case-insensitive matching using .lower() is a good practice, and the placement before the existing DEFAULT_GENERATED logic is appropriate since these function calls should be translated regardless of the column_extra value.

tests/unit/mysql_to_sqlite3_test.py (1)

116-116: Comprehensive test coverage for the new MySQL function translations!

The test cases correctly cover all four MySQL default value functions that were added in the implementation. The expected outputs match the implementation logic, and using column_extra=None appropriately tests the new functionality that doesn't depend on the DEFAULT_GENERATED flag.

Also applies to: 119-119, 132-133

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@techouse techouse changed the title 🐛 handle curtime(), curdate(), and, current_timestamp() and now() MariaDB specific translations in default values ✨ handle curtime(), curdate(), current_timestamp() and now() MariaDB specific translations in default values Jul 3, 2025
@techouse techouse added enhancement New feature or request and removed bug Something isn't working labels Jul 3, 2025
@techouse techouse changed the title ✨ handle curtime(), curdate(), current_timestamp() and now() MariaDB specific translations in default values ✨ handle curtime(), curdate(), current_timestamp() and now() MariaDB specific translations in default values Jul 3, 2025
Copy link

codecov bot commented Jul 3, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 94.40%. Comparing base (cdee3da) to head (0f774fc).
Report is 3 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #100      +/-   ##
==========================================
+ Coverage   94.34%   94.40%   +0.05%     
==========================================
  Files           8        8              
  Lines         637      643       +6     
==========================================
+ Hits          601      607       +6     
  Misses         36       36              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@techouse techouse changed the title ✨ handle curtime(), curdate(), current_timestamp() and now() MariaDB specific translations in default values ✨ handle curtime(), curdate(), current_timestamp(), and now() MariaDB specific translations in default values Jul 3, 2025
@techouse techouse changed the title ✨ handle curtime(), curdate(), current_timestamp(), and now() MariaDB specific translations in default values ✨ handle curtime(), curdate(), current_timestamp(), and now() MariaDB-specific translations in default values Jul 3, 2025
@techouse techouse added bug Something isn't working mariadb MariaDB specific and removed enhancement New feature or request labels Jul 3, 2025
@techouse techouse changed the title ✨ handle curtime(), curdate(), current_timestamp(), and now() MariaDB-specific translations in default values 🐛 handle curtime(), curdate(), current_timestamp(), and now() MariaDB-specific translations in default values Jul 3, 2025
@zokkis
Copy link

zokkis commented Jul 3, 2025

Testet localy and its working

Copy link

@zokkis zokkis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dont know if I have permissions to approve

@techouse techouse merged commit 29ce9c7 into master Jul 3, 2025
83 checks passed
@techouse techouse deleted the fix/mariadb-current-timestamp branch July 3, 2025 20:34
@techouse
Copy link
Owner Author

techouse commented Jul 3, 2025

Testet localy and its working

Thanx for confirming. I'll release this ASAP. Released in v2.4.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working mariadb MariaDB specific
Projects
None yet
Development

Successfully merging this pull request may close these issues.

mariadb default for current_timestamp
2 participants